package handler

import (
	"common"
	"common/biz"
	"core/repo"
	"core/service"
	"encoding/json"
	"framework/remote"
	"go.uber.org/zap"
	"hall/models/request"
	"hall/models/response"
)

/**
UserHandler UpdateUserAddress get param,session:%v,msg:%v&{0xc0003c8100 0xc000130100}{"addr
ess":"{\"x\":67.228,\"y\":88.983}","location":""}


*/

type UserHandler struct {
	userService *service.UserService
}

func (u *UserHandler) UpdateUserAddress(session *remote.Session, msg []byte) any {
	zap.S().Info("UserHandler UpdateUserAddress get param,session:%v,msg:%v", session, string(msg))
	var req request.UpdateUserAddressReq
	err := json.Unmarshal(msg, &req)
	if err != nil {
		return common.F(biz.RequestDataError)
	}
	err = u.userService.UpdateUserAddressByUid(session.GetUid(), req)
	if err != nil {
		return common.F(biz.SqlError)
	}
	var res response.UpdateUserAddressResponse
	res.Code = biz.OK
	res.UpdateUserData = req
	return res
}

/*
*
初始化userHandler
*/
func NewUserHandler(r *repo.Manager) *UserHandler {
	return &UserHandler{
		userService: service.NewUserService(r),
	}
}
